<!--  -->
<template>
    <div v-show="isShow">
        <el-dialog :title="dialogTitle" :visible.sync="editVisible" width="60%">
            <!-- <div class="handle-box">
                查询条件：
                <el-input class="handle-input mr10" size="mini" v-model="queryData.text01"></el-input>
                <el-select
                    v-model="queryData.address"
                    size="mini"
                    placeholder="地址"
                    class="handle-select mr10"
                >
                    <el-option key="1" label="广东省" value="广东省"></el-option>
                    <el-option key="2" label="湖南省" value="湖南省"></el-option>
                </el-select>
                <el-input
                    v-model="queryData.text02"
                    size="mini"
                    placeholder="用户名"
                    class="handle-input mr10"
                ></el-input>
                <el-button type="primary" size="mini" icon="el-icon-search" @click="handleSearch">搜索</el-button>
            </div>-->
            <div class="tree-box">
                <el-table
                    :data="tableData"
                    border
                    ref="multipleTable"
                    @select="handleSelect"
                    @select-all="onSelectAll"
                    height="220"
                >
                    <el-table-column type="selection" width="60" align="center"></el-table-column>
                    <el-table-column label="序号" type="index" align="center"></el-table-column>
                    <el-table-column prop="currCode" label="币别名称"></el-table-column>
                    <el-table-column prop="rate" label="汇率"></el-table-column>
                </el-table>
                
            </div>
           
            <span slot="footer" class="dialog-footer">
                <el-button @click="close">取 消</el-button>
                <el-button type="primary" @click="saveEdit">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import appMain from '../../utils/app_main.js';
var _ = require('lodash');
export default {
    props: {
        isShow: false,
        dialogTitle: '',
        method: '' // 列表要请求的方法
    },
    data() {
        return {
            editVisible: false,
            query: {
                ruleCode: '', // 单别代码	
                systemModel: '', // 系统模块
            },
            currentRow: '',
            //列表数据
            tableData: [],
            // 分页信息
            pagination: {
                pageIndex: 1,
                pageSize: 10,
                pageTotal: 60
            },
        };
    },
    methods: {
        // 勾选的时候来判断 让其变成单选
        handleSelect(val, row) {
            if (val.length > 1) {
                this.$refs.multipleTable.clearSelection(); // 清空所有选择
                val.shift();
                this.$refs.multipleTable.toggleRowSelection(row); //  选中当前选择
            }

            let selected = val.length && val.indexOf(row) !== -1;
            //console.log('handleSelect', selected); // true就是选中，0或者false是取消选中
            //console.log('handleSelect', row);
            if (selected) {
                this.currentRow = row;
            } else {
                this.currentRow = {};
            }
        },
        handleSearch() {
            // getTree()
        },
        // 获取树的数据
        findAllPage() {
            //发送请求获取树数据
            let sendData = {
                pageNo: this.pagination.pageIndex,
                pageSize: this.pagination.pageSize,
                record: this.query
            }
            appMain[this.method](sendData)
                .then(res => {
                    if (res.data.code === 20000) {
                        // this.tree = res.data;
                        //this.data = appMain.dealTree(res.data.data);
                        this.tableData = res.data.data;
                        
                    } else {
                        this.$message.error('服务器繁忙，请稍后再试');
                    }
                })
                .catch(err => {
                    console.log(err);
                });
        },
       
        //分页导航
        handlePageChange(val) {
           this.$set(this.pagination, 'pageIndex', val);
            console.log('pageChange:', this.pagination);
            //分页变化--请求接口
            this.findAllPage();
        },
        onSelectAll() {
            this.$refs.multipleTable.clearSelection(); //这个是清除所有选择项，当选择全部时，清除所有选择项
            this.currentRow = {};
        },
        close() {
            this.$emit('close', {
                showDialog: false
            });
        },
        // 从弹窗返回主页面的数据
        saveEdit() {
            //let item = this.tableDataIndex === '' ? {} : this.tableData[this.tableDataIndex];
            this.$emit('edit', { backData: this.currentRow, showDialog: false });
        }
    },
    watch: {
        isShow: function(newVal, oldVal) {
            //console.log(newVal, 'newVal');
            if (newVal == true) {
                this.editVisible = true;
                this.tableData = [];
                this.pagination = {
                    pageIndex: 1,
                    pageSize: 10,
                    pageTotal: 60
                }
                this.findAllPage();
            } else {
                this.editVisible = false;
            }
        },
        editVisible: function(newVal) {
            if (!this.editVisible) {
                this.$emit('close', {
                    showDialog: newVal
                });
            }
            
        }
    },
    computed: {
        aNum() {
            return 123;
        }
    },
    created() {}
};
</script>

<style lang="css" scoped>
.el-dialog__body {
    padding: 0 20px 30px;
}
.handle-input {
    width: 120px;
    display: inline-block;
}
.handle-select {
    width: 120px;
}
.tree-box {
    border: 1px solid #ddd;
    margin-top: 20px;
    height: 300px;
}
.flex-left {
    width: 200px;
    border-right: 1px solid #ddd;
}
.flex-right {
    flex: 1;
}
</style>